package com.lalilu.homework9.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lalilu.homework9.R;
import com.lalilu.homework9.service.MusicService;

import org.jetbrains.annotations.NotNull;


public class MusicFragment extends Fragment {

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        Button _start = view.findViewById(R.id.music_start);
        Button _end = view.findViewById(R.id.music_stop);

        _start.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), MusicService.class);
            requireActivity().startService(intent);
        });

        _end.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), MusicService.class);
            requireActivity().stopService(intent);
        });
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_music, container, false);
    }
}